package cn.shop.front.util;

import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.http.HttpHeaders;

import javax.servlet.http.HttpServletRequest;

public class AliasUtil {

    private final static String DEFAULT_HOST = "www";

    public static String getAlias(HttpServletRequest request) {
        String header = request.getHeader(HttpHeaders.REFERER);
        if (StrUtil.isNotBlank(header)) {
            /*if (header.contains("jinyuntongpay.com")) {
                return StrUtil.blankToDefault(ReUtil.get("(?<=://)[a-zA-Z0-9-_]+(?=.jinyuntongpay.com)", header, 0), DEFAULT_HOST);
            }*/
            return StrUtil.blankToDefault(ReUtil.get("(?<=://)[a-zA-Z0-9-_]+(?=.*.com)", header, 0), DEFAULT_HOST);
        }
        return DEFAULT_HOST;
    }

}
